﻿
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using OA.Model;
using OA.Web.Attribute;
using OA.Web.Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;


namespace OA.Web.Areas.Member.Controllers
{
    public class OfficialDocumentController : BaseMemberController
    {
        private IMemoryCache _cache;
        private ICookie _cookie;
        public OfficialDocumentController(ICookie cookie, IHttpContextAccessor accessor, IMemoryCache cache) : base(accessor, cookie, cache)
        {
            _cache = cache;
            _cookie = cookie;
        }

        [MyActionFilter("203003", "红头文件", "通知公告", true, "iconguizhangzhidu")]
        public IActionResult Index()
        {
            return View();
        }

        [MyActionFilter("203003", "红头文件")]
        public IActionResult GetData(string keyword, int page = 1, int limit = 12)
        {
            Expression<Func<Notice, bool>> where = m => m.Type == "红头文件";
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                where = m => m.Type == "公司公告" && (m.Title.Contains(keyword));
            }
            PageList<SimpleNotice> list = this.GetPageList<Notice, SimpleNotice>(where, page, limit, SimpleNotice.Map);
            var result = new
            {
                code = "0",
                msg = "",
                count = list.RowCount,
                data = list.List
            };
            return Json(result);
        }

        [HttpGet]
        [MyActionFilter(key: "203003", name: "红头文件")]
        public IActionResult Details(int id)
        {
            Notice infoNotice = this.dbContextFactory.DbContext.Notice.Where(m => m.ID == id).FirstOrDefault();
            if (infoNotice == null || infoNotice.Type != "红头文件")
            {
                return Redirect("/Member/Tips/Index?msg=您查看的红头文件不存在");
            }
            return View(infoNotice);
        }
    }
}